package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroAppReferDao;
import com.ctg.itrdc.imageconsole.data.entity.DockerMicroAppRefer;
import com.ctg.itrdc.paspsdk.common.entity.PageInfo;
import com.ctg.itrdc.paspsdk.common.utils.type.StringUtils;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;
import com.ctg.itrdc.paspsdk.data.entity.ClassInfoUtils;

/**
 * 
 * @Description 
 * @author wupiao
 * @since 2017年2月23日
 */
@Component("dockerMicroAppReferDao")
public class DockerMicroAppReferDaoImpl extends BaseDaoImpl implements IDockerMicroAppReferDao {

	public PageInfo<DockerMicroAppRefer> jdbcFindPageInfo(DockerMicroAppRefer appRefer, int currentPage, int perPageNum) {
		String columnsName = ClassInfoUtils.getColumnsName(DockerMicroAppRefer.class);
		String tableName = ClassInfoUtils.getTableName(DockerMicroAppRefer.class);
		StringBuilder sql = new StringBuilder(" SELECT ");
		sql.append(columnsName).append(" FROM ").append(tableName).append(" A WHERE 1=1 ");

		List<Object> params = new ArrayList<Object>();
		if (appRefer.getId()!=null) {
			sql.append(" AND ID = ? ");
			params.add(appRefer.getId());
		}
		if (StringUtils.isNotEmpty(appRefer.getName())) {
			sql.append(" AND NAME LIKE ? ");
			params.add("%" + appRefer.getName() + "%");
		}
		sql.append(" AND CREATE_USER_ID = ?  ORDER BY LAST_UPDATE_TIME DESC");
    	params.add(appRefer.getCreateUserId());

		return (PageInfo<DockerMicroAppRefer>) this.jdbcFindPageInfo(sql.toString(), DockerMicroAppRefer.class, params,
				currentPage, perPageNum, true);
	}

}
